<!DOCTYPE html>
<!-- ng-app -->
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="../../../js/plugins/angular/angular.min.js" type="text/javascript"></script>
    <script src="../../../js/plugins/angular/angular-route.min.js" type="text/javascript"></script>
</head>
<body>
    <!-- ng-view作为装载不同模板的容器，所有切换后的都在该容器中展示 -->
    <div ng-view></div>

    <script>
        var app = angular.module('app',['ngRoute']);
        app.controller('index',['$scope',function ($scope) {
            $scope.students = students;
        }]);
        app.controller('book',['$scope',function ($scope,$routeParams) {
            for (var i=0;i<students.length;i++){
                if(students[i].stuId == $routeParams.id){

                    $scope.student = students[i];
                    break;
                }
            }
        }]);

        app.config(['$routeProvider',function ($routeProvider) {
            $routeProvider
                .when('/',{
                    controller:'index',
                    templateUrl:"5-6-view-data-index.html"
                })
                .when('/view/:id',{
                    controller:'book',
                    templateUrl:"5-6-view-data-book.html",
                    publicAccess:true
                })
                .otherwise({
                    /* 没有匹配到，调到index */
                    redirectTo:'/'
                })
        }]);
        var students = [
            { stuId:100, name:"明明", sex:"女", score:60},
            { stuId:101, name:"哈哈", sex:"女", score:45},
            { stuId:102, name:"花花", sex:"男", score:66},
            { stuId:103, name:"嘿嘿", sex:"女", score:4}
        ]
    </script>
</body>
</html>